package com.xbq.exceleditor.ui.excel;

import android.webkit.JavascriptInterface;

import androidx.annotation.Keep;

import com.google.gson.Gson;

/**
 * Rich Editor Callback
 *
 * @author even.wu
 * @date 8/8/17
 */

@Keep
public class RichEditorCallback {
    private String data;
    private String fileBase64;
    private Gson gson = new Gson();
    private String html;
    private OnGetHtmlListener onGetHtmlListener;
    private OnGetDocxListener onGetDocxListener;
    private OnGetHtmlAndDocxListener onGetHtmlAndDocxListener;


    @JavascriptInterface public void returnHtml(String html) {
        this.html = html;
        if (onGetHtmlListener != null) {
            onGetHtmlListener.getHtml(html);
        }
    }
    @JavascriptInterface public void returnDocx(String docxBase64) {
        if (onGetDocxListener != null) {
            onGetDocxListener.getDocx(docxBase64);
        }
    }

    @JavascriptInterface public void returnHtmlAndDocx(String html, String docxBase64) {
        if (onGetHtmlAndDocxListener != null) {
            onGetHtmlAndDocxListener.getHtmlAndDocx(html,docxBase64);
        }
    }

    @JavascriptInterface
    public String getData() {
        return data;
    }
    @JavascriptInterface
    public String getFileBase64() {
        return fileBase64;
    }

    public RichEditorCallback setData(String data) {
        this.data = data;
        return this;
    }


    public RichEditorCallback setFileBase64(String fileBase64) {
        this.fileBase64 = fileBase64;
        return this;
    }

    public interface OnGetHtmlListener {
        void getHtml(String html);
    }

    public interface OnGetDocxListener {
        void getDocx(String docxBase64);
    }


    public interface OnGetHtmlAndDocxListener {
        void getHtmlAndDocx(String html, String docxBase64);
    }


    public OnGetHtmlListener getOnGetHtmlListener() {
        return onGetHtmlListener;
    }

    public void setOnGetHtmlListener(OnGetHtmlListener onGetHtmlListener) {
        this.onGetHtmlListener = onGetHtmlListener;
    }

    public OnGetDocxListener getOnGetDocxListener() {
        return onGetDocxListener;
    }

    public void setOnGetDocxListener(OnGetDocxListener onGetDocxListener) {
        this.onGetDocxListener = onGetDocxListener;
    }

    public OnGetHtmlAndDocxListener getOnGetHtmlAndDocxListener() {
        return onGetHtmlAndDocxListener;
    }

    public void setOnGetHtmlAndDocxListener(OnGetHtmlAndDocxListener onGetHtmlAndDocxListener) {
        this.onGetHtmlAndDocxListener = onGetHtmlAndDocxListener;
    }

}
